<%--
  Created by IntelliJ IDEA.
  User: 长安
  Date: 2020/3/15
  Time: 17:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="js/jquery.min.js"></script>
    <script>
        $(function () {
            $("#btn").click(function () {
                //alert("hello btn")
                //发送ajax请求
                $.ajax({
                    //请求服务区的url
                    url:"user/testAjax",
                    //发送给服务器数据的编码类型
                    contentType:"application/json;charset=UTF-8",
                    //发送到服务器的数据
                    data:'{"username":"hehe","password":"123456","age":"18"}',
                    //预期服务器返回的数据类型
                    dataType:"json",
                    //请求方式
                    type:"post",
                    //请求成功后的回调函数：将服务器返回的数据进行处理或者显示
                    success:function (data){
                        //将服务器响应的json数据进行解析
                        alert(data);
                        alert(data.username);
                        alert(data.password);
                        alert(data.age)
                    }
                });
            });
        });
    </script>
</head>
<body>
    <a href="user/string">String类型</a>
    <br>
    <a href="user/void">void类型</a>
    <br>
    <a href="user/testModelAndView">testModelAndView</a>
    <br/>
    <a href="user/stringForwordandRedirect">关键字跳转</a>
    <br>

    <button id="btn">发送ajax请求</button>
</body>
</html>
